package com.services.impl;

import com.dao.IFlightManageDao;
import com.dao.impl.FlightManageDaoImpl;
import com.model.FlightModel;
import com.services.IFlightManageServices;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class FlightManageServicesImpl implements IFlightManageServices {
    private IFlightManageDao flightManageDao = new FlightManageDaoImpl();

    @Override
    public Map<String, Object> getFlightList(int page, int size, String query) throws Exception {
        Map<String, Object> result = new HashMap<>();
        
        // 计算分页
        int offset = (page - 1) * size;
        
        // 获取航班列表和总数
        List<FlightModel> flights = flightManageDao.getFlightList(offset, size, query);
        int total = flightManageDao.getFlightCount(query);
        
        result.put("list", flights);
        result.put("total", total);
        
        return result;
    }

    @Override
    public FlightModel createFlight(FlightModel flight) throws Exception {
        // 设置初始状态为未上架
        flight.setStatus("INACTIVE");
        return flightManageDao.createFlight(flight);
    }

    @Override
    public FlightModel updateFlight(FlightModel flight) throws Exception {
        return flightManageDao.updateFlight(flight);
    }

    @Override
    public void deleteFlight(Integer flightId) throws Exception {
        flightManageDao.deleteFlight(flightId);
    }

    @Override
    public void updateFlightStatus(Integer flightId, String status) throws Exception {
        flightManageDao.updateFlightStatus(flightId, status);
    }
} 